package kosta.model.member;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class MemberDaoImpl implements MemberDao{
	@Resource(name="sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;
	
	@Override
	public MemberVO login(MemberVO mvo) throws Exception {
		return sqlSessionTemplate.selectOne("member.login", mvo);
	}

	@Override
	public MemberVO idCheck(String id) throws Exception {
		return sqlSessionTemplate.selectOne("member.idCheck", id);
	}

	@Override
	public void update(MemberVO mvo) throws Exception {
		sqlSessionTemplate.update("member.update", mvo);
	}

	@Override
	public void leaveMember(String id) throws Exception {
		sqlSessionTemplate.delete("member.leaveMember", id);
	}

	@Override
	public void register(MemberVO mvo) throws Exception {
		System.out.println(mvo + "-------------- DaoImpl");
		sqlSessionTemplate.insert("member.register", mvo);
	}

	@Override
	public List<TestVO> testList(int grade) throws Exception {
		return sqlSessionTemplate.selectList("test.testList", grade);
	}

	@Override
	public void gradeUp(MemberVO mvo) throws Exception {
		sqlSessionTemplate.update("member.gradeUp", mvo);
	}

	@Override
	public void plusPoint(String id) throws Exception {
		this.sqlSessionTemplate.update("member.plusPoint", id);
	}

	@Override
	public void minusPoint(String id) throws Exception {
		this.sqlSessionTemplate.delete("member.minusPoint", id);
	}
	//관리자 페이지(박세미)//////////////////////////////////////////////////////////
		////Member관리////
		@Override
		public List<MemberVO> getAllMember(String id) throws Exception {
			return sqlSessionTemplate.selectList("member.getAllMember",id);
		}
		@Override
		public List<MemberVO> findMemberByGrade(HashMap map) throws Exception {
			return sqlSessionTemplate.selectList("member.findMemberByGrade", map);
		}
		@Override
		public void outMember(String id) throws Exception {
			sqlSessionTemplate.delete("member.outMember",id);
			
		}
		////Test관리////

		@Override
		public List<TestVO> getAllTest(String question) throws Exception {
			return sqlSessionTemplate.selectList("member.getAllTest",question);
		}

		@Override
		public List<TestVO> gradeByTest(HashMap map) throws Exception {
			return sqlSessionTemplate.selectList("member.gradeByTest",map);
		}

		@Override
		public void updateTest(TestVO tvo) throws Exception {
			sqlSessionTemplate.update("member.updateTest",tvo);
		}

		@Override
		public TestVO findByTest(int no) throws Exception {
			return sqlSessionTemplate.selectOne("member.findByTest",no);
		}

		@Override
		public void removeTest(int no) throws Exception {
			sqlSessionTemplate.delete("member.removeTest",no);
		}

		@Override
		public void insertTest(TestVO tvo) {
			sqlSessionTemplate.insert("member.insertTest",tvo);
		}
		
		//////////////// rank
		@Override
		public MemberVO myLankView(String id) throws Exception {
			return sqlSessionTemplate.selectOne("member.myLankView", id);
		}

		@Override
		public MemberLankVO findByLankID(String id) throws Exception {
			return sqlSessionTemplate.selectOne("member.findByLankID", id);
		}

		@Override
		public void insertMyLank(HashMap map) throws Exception {
			sqlSessionTemplate.insert("member.insertMyLank", map);
		}

		@Override
		public void updateMyLank(HashMap map) throws Exception {
			sqlSessionTemplate.update("member.updateMyLank", map);
		}

		@Override
		public MemberLankVO findByLankIdCount(String id) throws Exception {
			return sqlSessionTemplate.selectOne("member.findByLankIdCount", id);
		}
}
